﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace MemberManagement;

public class MemberCreateParameter : MemberCreateOrUpdateParameterBase
{
    [EmailAddress]
    [MaxLength(256)]
    public virtual string AdminEmailAddress { get; set; }

    [Phone]
    [MaxLength(20)]
    public virtual string AdminPhoneNumber { get; set; }

    [Required]
    [MaxLength(128)]
    public virtual string AdminPassword { get; set; }

    public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
    {
        var list = base.Validate(validationContext)?.ToList() ?? new List<ValidationResult>();
        if (AdminEmailAddress.IsNullOrWhiteSpace() && AdminPhoneNumber.IsNullOrWhiteSpace())
        {
            list.Add(new ValidationResult("Phone number and email address must be filled in one.", new[] { nameof(AdminPhoneNumber), nameof(AdminEmailAddress) }));
        }
        return list;
    }
}
